package ru.ipo.dces.plugins.admin.components;

import info.clearthought.layout.TableLayout;
import ru.ipo.dces.clientservercommunication.ContestDescription;

import javax.swing.*;
import java.awt.*;

public class ContestDescriptionPanel extends JPanel {
    private JTextPane contestDescriptionTextPane;
    private static final int separatorGap = 5;

    public ContestDescriptionPanel() {
        setLayout(new TableLayout(new double[]{separatorGap, TableLayout.FILL},
                new double[]{separatorGap, TableLayout.FILL}));
        contestDescriptionTextPane = new JTextPane();
        contestDescriptionTextPane.setBackground(getBackground());
        contestDescriptionTextPane.setBorder(null);
        contestDescriptionTextPane.setEditable(false);
        contestDescriptionTextPane.setDisabledTextColor(Color.BLACK);
        contestDescriptionTextPane.setFocusable(false);
        contestDescriptionTextPane.setContentType("text/html");
        add(contestDescriptionTextPane, "1, 1");
    }

    public void setContest(ContestDescription contest) {
        if (contest == null) {
            resetPanel();
            return;
        }
        String desc = contest.description;
        contestDescriptionTextPane.setText(desc);
    }

    public void resetPanel() {
        contestDescriptionTextPane.setText("");
    }
}
